package com.haoshuang.zhouzhoubang.ui.page.shop.address.area

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.CityBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ServiceAreaViewModel : BaseViewModel() {
    val getData = StatefulMutableLiveData<ArrayList<CityBean>>()
        fun getData(vararg params: Pair<String, Any?>) {
            rxLifeScope.launch {
                request<ArrayList<CityBean>>("/api/City/getRegionNameByParentId", *params,
                    onStart = {
                        getData.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        getData.value = StateData.Error(code, msg)
                    }, onSuccess = {
                        getData.value = StateData.Success(it)
                    })
            }
        }
    val getData1 = StatefulMutableLiveData<ArrayList<CityBean>>()
    fun getData1(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<CityBean>>("/api/City/getRegionNameByParentId", *params,
                onStart = {
                    getData1.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData1.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData1.value = StateData.Success(it)
                })
        }
    }
    val getData2 = StatefulMutableLiveData<ArrayList<CityBean>>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<CityBean>>("/api/City/getRegionNameByParentId", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.value = StateData.Success(it)
                })
        }
    }
}